home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiniExamples / AppKit / ZooView / Controller.m < prev    next >
Text File  |  1995-06-12  |  2KB  |  85 lines

  1.  
  2. /* 
  3.  * Controller.m
  4.  *
  5.  * Purpose:
  6.  *        This object serves as the browsers delegate, and does some initialization.
  7.  *
  8.  * You may freely copy, distribute, and reuse the code in this example.
  9.  * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  10.  * fitness for any particular use.
  11.  *
  12.  * Written by: Mary McNabb
  13.  * Created: Apr 91
  14.  *
  15.  */
  16.  
  17. #import "Controller.h"
  18. #import "RightSubView.h"
  19. #import "SideSplitView.h"
  20.  
  21. #define MAXLEN 20        /* maximum number of chars in a name */
  22. #define NUM_ANIMALS 16     /* make sure this number matches the
  23.                          * number of strings in the following string table!! */
  24. char *animals[] = { "doug", "elizabeth", "flip", "george", "henry", "howard", "jeff", "julie", "kate", 
  25.     "leonard", "mai", "mary", "michelle", "sam", "tony", "dawn" };
  26.  
  27. @implementation Controller
  28.  
  29. /*
  30.  * take advantage of IB and initialize the browser from here
  31.  */
  32. - setTheBrowser:anObject
  33. {
  34.     theBrowser = anObject;
  35.     [theBrowser setDelegate:self];
  36.     [theBrowser reloadColumn:0];
  37.     return self;
  38. }
  39.  
  40. /*
  41.  * Since we have to resize the subviews don't put the window on screen
  42.  * until we get here
  43.  */
  44. - appDidInit:sender
  45. {
  46.     [zooSplitView initViews];
  47.     [[zooSplitView window] orderFront:self];
  48.     return self;
  49. }
  50.  
  51. /*
  52.  * the user selected a name. Tell the right sub view to display the picture.
  53.  */
  54. - browserCellWasSelected:sender
  55. {
  56.     char path[MAXLEN];
  57.     char *p;
  58.  
  59.     [theBrowser getPath:path toColumn:1];
  60.     p = path; p++;            /* skip the separator which precedes the name */
  61.     [rightView setAnimalPicture:p];
  62.     return self;
  63. }
  64.  
  65. /*
  66.  * Fill the browser up with names from the string table.
  67.  */
  68. - (int)browser:sender fillMatrix:matrix inColumn:(int)column
  69. {
  70.     int i;
  71.     id newCell;
  72.     
  73.     for (i = 0; i < NUM_ANIMALS; i++) {
  74.         [matrix addRow];
  75.         newCell = [matrix cellAt:i :0];
  76.         [newCell setTag:(i * 16)];
  77.         [newCell setStringValue:animals[i]];
  78.         [newCell setLeaf:YES];
  79.         [newCell setLoaded:YES];
  80.     }
  81.     return i;
  82. }
  83.  
  84. @end
  85.